<?php


namespace App\Api\Controllers;


use App\Api\Manages\CommonController;

class PubController extends CommonController
{

    //用户发布
    /**
     * Redis 发布
     * @param $user_id  int 用户iD
     * @param $source_id    int  资源id
     * @return bool
     */
    function redis_publish()
    {
        //dd(1);
        $redis = new \Redis();
        $redis->connect('127.0.0.1',6379);
        echo 'reading c1 ...\n';
        $redis->set('aaaa','1213');
        //dd($redis->get('aaaa'));
     /*   //设置超时控制
        $redis->setOption(\Redis::OPT_READ_TIMEOUT,-1);*/
        $redis->subscribe(['c1'],function($redis){
            echo 'recieve message ';
        });
    }
    //发送一条消息
    public function redis_sub()
    {
        $redis = new \Redis();
        $redis->connect('127.0.0.1',6379);
        $res = $redis->publish('c1',111);
        echo 'clents'.$res;
    }
}